package com.tuzhi.gateway.utils;

import com.tuzhi.util.NumberTzUtil;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.http.server.reactive.ServerHttpRequest;

import java.util.List;

public class ServletUtils {

    public static String getHeader(ServerHttpRequest request, Object key) {
        List<String> list = request.getHeaders().get(key);
        if (CollectionUtils.isNotEmpty(list)) {
            return list.get(0);
        }
        return null;
    }

    public static Long getHeader4Long(ServerHttpRequest request, Object key) {
        String valStr = getHeader(request, key);
        if (StringUtils.isNotBlank(valStr) && NumberTzUtil.isNumeric(valStr)) {
            return Long.valueOf(valStr);
        }
        return null;
    }
}
